package com.xpgk.xpsoft.common;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.xpgk.common.controller.BaseController;
import com.xpgk.xpsoft.user.UserService;

public class XPSoftAuthInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		BaseController controller = (BaseController) inv.getController();
		int userID = controller.getCurUserID();
		String actionKey = inv.getActionKey();
		Integer rightID = XPSoftRight.getRightID(actionKey);
		if (rightID != null && !UserService.hasRight(userID, rightID)) {
			controller.renderError(404);
			return;
		}
		inv.invoke();
	}
}
